import React from 'react'
import { NavBar } from 'antd-mobile'


// 导入高阶组件 withRouter
import { withRouter } from 'react-router-dom'

// 导入props检验的包
import PropsType from 'prop-types'

// 导入样式
// import './index.scss'
import styles from './index.module.css'

function NavHeader({ children, history, onLeftClick }) {
  // 默认点击行为
  const defaultHandler = () =>  history.go(-1);
  return (
    <NavBar
      className={styles.navBar}
      mode="light"
      icon={
        <i className="iconfont icon-back" />
      }
      onLeftClick={ onLeftClick || defaultHandler }
    >
      {children}
    </NavBar>
  )
}

// 添加props校验
NavHeader.PropsType = {
  children: PropsType.string.isRequired,
  onLeftClick: PropsType.func
}

// withRouter(NavHeader) 函数的返回值也是一个组件
export default withRouter(NavHeader)
